﻿using System;
using System.Security.Cryptography;

namespace DreamCube.Foundation.Security
{
    public class RSA : ISecurity
    {
        #region "字段"

        /// <summary>
        /// xml字符串
        /// </summary>
        private String xmlString;

        #endregion

        public RSA(String xmlString)
        {
            this.xmlString = xmlString;
        }

        public Byte[] Encrypt(Byte[] data)
        {
            using (RSACryptoServiceProvider rsaprovider = new RSACryptoServiceProvider())
            {
                rsaprovider.FromXmlString(this.xmlString);
                return rsaprovider.Encrypt(data, false);
            }
        }

        public Byte[] Decrypt(Byte[] data)
        {
            using (RSACryptoServiceProvider rsaprovider = new RSACryptoServiceProvider())
            {
                rsaprovider.FromXmlString(this.xmlString);
                return rsaprovider.Decrypt(data, false);
            }
        }
    }
}
